#include<iostream>
#include<assert.h>
#include<string>
using namespace std;
namespace shiyue {

	template<class T>
	class vector {
	public:
		typedef T* iterator;
		typedef T* const_iterator;

		vector()
			:_start(nullptr)
			, _finish(nullptr)
			, _endofstorage(nullptr)
		{}

		vector(size_t n, const T& b = T())
			:_start(nullptr)
			, _finish(nullptr)
			, _endofstorage(nullptr)
		{
			reserve(n);
			while (n)
			{
				push_back(b);
				n--;
			}
		}
		void push_back(const T& f)
		{
			if (_finish == _endofstorage)
			{
				reserve(size());
			}
			*_finish  = f;
			_finish++;
		 }
		T* begin()
		{
			return _start;
		}
		T* end()
		{
			return _finish;
		}

		 T &operator[](size_t n)
		{
			 return  _start[n];
		}
		
		vector<T>&  reserve(size_t n)
		{
			if (n > capacity())
			{
				T* tempt = new T[n];
				for (size_t i = 0; i <size(); i++)
				{
					tempt[i] = _start[i];
				}
				size_t oldsize=size();
				_start = tempt;
				_finish = _start + oldsize;
				_endofstorage = _start+n;
			}
			 else
			{
				_finish = _start + n;
			}
			return *this;

		}
		size_t size()
		{
			return _finish - _start;
		}
		size_t capacity()
		{

			return _endofstorage - _start;

		}

		/*void swapall(vector<T>& a)
		{
			swap(_start, a._start);
			swap(_finish, a._finish);
			swap(_endofstorage, a._endofstorage);
		}*/
		~vector()
		{
			delete[]_start;
			_start = _endofstorage = _finish = nullptr;

		}
		void print()
		{
			iterator start = begin();
			while (start != end())
			{
				cout << *start << "";
				start++;
			}

		}

	private:
		iterator _start;
		iterator _finish;
		iterator _endofstorage;
	};
	












}